package router

import (
	"ErgoGo/internal/http/controllers"
	"ErgoGo/internal/http/middlewares"

	"github.com/gin-gonic/gin"
)

func RegisterAPIRoutes(r *gin.Engine) {
	// 路由设置
	r.GET("/login", controllers.LoginForm)
	r.POST("/login", controllers.Login)
	r.GET("/logout", controllers.Logout)

	// 需要认证的路由组
	authGroup := r.Group("/")
	authGroup.Use(middlewares.AuthRequired())
	{
		authGroup.GET("/", controllers.Dashboard)
		authGroup.GET("/dashboard", controllers.Dashboard)
		authGroup.GET("/generate", controllers.GenerateForm)
		authGroup.POST("/generate", controllers.GenerateArticle)
		authGroup.GET("/history", controllers.HistoryList)
		authGroup.GET("/history/:id", controllers.HistoryDetail)
		authGroup.DELETE("/history/:id", controllers.HistoryDelete)
		authGroup.DELETE("/history", controllers.HistoryBatchDelete)
		authGroup.POST("/publish/:id", controllers.PublishArticle)

		// 设置页面路由
		authGroup.GET("/settings", controllers.SettingsForm)
		authGroup.POST("/settings", controllers.SettingsSave)
	}
}
